home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / Telephone Manager / Stiletto Sources / Sources / DNWindow.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-05  |  48.8 KB  |  1,932 lines  |  [TEXT/MPS ]

  1. /************************************************************************************************/
  2. /*                                                                                                */
  3. /*    Program Name:    Stiletto                                                                    */
  4. /*                                                                                                */
  5. /*    File Name:        DNWindow.c                                                                    */
  6. /*                                                                                                */
  7. /*    © Apple Computer, Inc. 1991-1995                                                            */
  8. /*    All Rights Reserved                                                                            */
  9. /*                                                                                                */
  10. /*    Revision History:                                                                            */
  11. /*                                                                                                */
  12. /*        Date        Who                    Modification                                            */
  13. /*                                                                                                */
  14. /*        1991-07-05    Chris Halim            Original version                                        */
  15. /*        1995-06-26    Jaakko Railo        Version 2.0                                                */
  16. /*                                                                                                */
  17. /************************************************************************************************/
  18.  
  19. /****************************************** DESCRIPTION ******************************************
  20.  
  21. *************************************************************************************************/
  22.  
  23. /******************************************** HEADERS *******************************************/
  24.  
  25. #include "Resources.h"
  26. #include "stdio.h"
  27. #include "ToolUtils.h"
  28.  
  29. #ifndef __TELEPHONES__
  30. #include "Telephones.h"
  31. #endif
  32.  
  33. #include "CAHandlers.h"
  34. #include "Constants.h"
  35. #include "DNHandlers.h"
  36. #include "DNWindow.h"
  37. #include "LogWindow.h"
  38. #include "TermWindow.h"
  39. #include "Utilities.h"
  40.  
  41. /****************************************** DEFINITIONS *****************************************/
  42.  
  43. /****************************************** PROTOTYPES ******************************************/
  44.  
  45. void    AttachDNWindowControls (DNWindowPtr dnWindow, TELDNHandle dnHand);
  46. Boolean    DoDNWindowMouseDown (const EventRecord *theEvent);
  47. void    DoDNWindowActivate (WindowPtr theWindow, Boolean becomingActive);
  48. void    DoDNWindowUpdate (WindowPtr theWindow);
  49. void    DoDNWindowClick (WindowPtr theWindow, const EventRecord * theEvent);
  50. void    DoDNWindowOSEvent (const EventRecord *theEvent);
  51. void     DoDNWindowSuspend (Boolean doClipConvert);
  52. void     DoDNWindowResume (Boolean doClipConvert);
  53.  
  54. OSErr    CreateCAList (DNWindowPtr dnWindow);
  55. void    DisposeCAList (DNWindowPtr dnWindow);
  56. OSErr    DummyCreateCAWindowList (DNWindowPtr dnWindow);
  57. OSErr    CreateCAWindowList (DNWindowPtr dnWindow);
  58.  
  59. void    DisplaySelectedCAs (DNWindowPtr dnWindow);
  60. void    DumpSelectedCAInfo (DNWindowPtr dnWindow);
  61. void    DumpSelectedCAState (DNWindowPtr dnWindow);
  62. void    ShowCAWindow (DNWindowPtr dnWindow, short whichCA);
  63.  
  64. void    PrepareForwardDLOGUserItems (DialogPtr theDialog);
  65. pascal    Boolean ForwardDLOGFilterProc (DialogPtr theDialog, EventRecord * theEvent, short *itemHit);
  66. short    DisplayForwardDialog (DNWindowPtr dnWindow);
  67. void    PutForwardAttribToDialog (DialogPtr theDialog, ForwardAttribHandle theForwardAttrib);
  68. void    PutDialogSetupToForwardAttrib (DialogPtr theDialog, ForwardAttribHandle theForwardAttrib);
  69.  
  70. OSErr    SetForwarding (DNWindowPtr dnWindow);
  71. OSErr    CancelForwarding (DNWindowPtr dnWindow);
  72. void    HandleForward (DNWindowPtr theWindow, short * value);
  73.  
  74. TELCAHandle    GetAvailableCA (void);
  75.  
  76. short    GetANumber (void);
  77.  
  78. void    HandleMakeACall (DNWindowPtr theWindow);
  79. void    HandleIntercom (DNWindowPtr theWindow, short modifiers);
  80. void    HandlePaging (DNWindowPtr theWindow, short modifiers);
  81. void    HandleCallPickup (DNWindowPtr theWindow, short modifiers);
  82. void    HandleVoiceMail (DNWindowPtr theWindow, short modifiers);
  83. void    HandleRetrievePark (DNWindowPtr theWindow, short modifiers);
  84. void    HandleCallBackNow (DNWindowPtr theWindow, short modifiers);
  85.  
  86. void    HandleDND (DNWindowPtr dnWindow, short * value);
  87. void    PrepareDNDDLOGUserItems (DialogPtr theDialog);
  88. short    DisplayDNDDialog (DNWindowPtr dnWindow);
  89. void    PutDNDAttribToDialog (DialogPtr theDialog, DNDAttribHandle theDNDAttrib);
  90. void    PutDialogSetupToDNDAttrib (DialogPtr theDialog, DNDAttribHandle theDNDAttrib);
  91. OSErr    SetDND (DNWindowPtr dnWindow);
  92. OSErr    CancelDND (DNWindowPtr dnWindow);
  93.  
  94. void    PrepareCallPickupDLOGUserItems (DialogPtr theDialog);
  95. short    DisplayCallPickupDialog (DNWindowPtr dnWindow);
  96. void    PutCallPickupAttribToDialog (DialogPtr theDialog, CallPickupAttribHandle theCallPickupAttrib);
  97. void    PutDialogSetupToCallPickupAttrib (DialogPtr theDialog, CallPickupAttribHandle theCallPickupAttrib);
  98.  
  99. void    PrepareMakeACallDLOGUserItems (DialogPtr theDialog);
  100. short    DisplayMakeACallDialog (DNWindowPtr dnWindow);
  101. void    PutMakeACallAttribToDialog (DialogPtr theDialog, MakeACallAttribHandle theMakeACallAttrib);
  102. void    PutDialogSetupToMakeACallAttrib (DialogPtr theDialog, MakeACallAttribHandle theMakeACallAttrib);
  103.  
  104. void    PrepareGetParkIDDLOGUserItems (DialogPtr theDialog);
  105. short    DisplayGetParkIDDialog (Str255 parkID);
  106.  
  107. short    SearchCAList (DNWindowPtr dnWindow, TELCAHandle caHand);
  108.  
  109. short    GetCAIndex (DNWindowPtr dnWindow, TELCAHandle caHand);
  110.  
  111. /******************************************** GLOBALS *******************************************/
  112.  
  113. extern    LogWindowPtr        gLogWindow;
  114. extern    TelWindowPtr        gTelWindow;
  115.  
  116. extern    TELCAHandle            gAvailableCA;
  117.  
  118. extern    TelephoneDNMsgUPP    gDNMsgHandlerUPP;
  119. extern    TelephoneCAMsgUPP    gCAMsgHandlerUPP;
  120. extern    TelephoneCAMsgUPP    gCAActiveMsgHandlerUPP;
  121. extern    ModalFilterUPP        gStandardFilterUPP;
  122. extern    UserItemUPP            gDrawBoxUPP;
  123. extern    UserItemUPP            gDrawDefaultUPP;
  124.  
  125. /************************************************************************************************/
  126. /************************************************************************************************/
  127.  
  128.  
  129. #pragma segment DNWindow
  130. Boolean    IsHandledByDNWindowList (DNWindowPtr dnWindowList, const EventRecord * theEvent)
  131. {
  132.     Boolean        wasHandled = false;
  133.     DNWindowPtr tDNWindow = dnWindowList;
  134.     
  135.     while (tDNWindow && !(wasHandled = IsHandledByDNWindow (tDNWindow, theEvent))) {
  136.         tDNWindow = tDNWindow->next;
  137.     }
  138.     
  139.     return (wasHandled);
  140. }
  141.  
  142.  
  143. Boolean    IsHandledByDNWindow (DNWindowPtr dnWindow, const EventRecord * theEvent)
  144. {
  145.     WindowPtr    theWindow;
  146.     Boolean        wasHandled = false;
  147.     char        key;
  148.     OSErr        errCode;
  149.     
  150.     if (dnWindow != nil) {
  151.         if ((wasHandled = IsHandledByCAWindowList (dnWindow->fCAWindowList, theEvent)) == false) {
  152.  
  153.             switch ( theEvent->what ) {
  154.                 case mouseDown:
  155.                     (void) FindWindow(theEvent->where, &theWindow);
  156.                     if (theWindow == (WindowPtr) dnWindow) {
  157.                         wasHandled = DoDNWindowMouseDown (theEvent);
  158.                     }
  159.                     break;
  160.                                 
  161.                 case activateEvt:
  162.                     if ((DNWindowPtr) theEvent->message == dnWindow) {
  163.                         DoDNWindowActivate ((WindowPtr) dnWindow, (theEvent->modifiers & activeFlag) != 0);
  164.                         wasHandled = true;
  165.                     }
  166.                     break;
  167.                     
  168.                 case updateEvt:
  169.                     if ((DNWindowPtr) theEvent->message == dnWindow) {
  170.                         DoDNWindowUpdate ((WindowPtr) dnWindow);
  171.                         wasHandled = true;
  172.                     }
  173.                     break;
  174.                     
  175.                 case osEvt:
  176.                     if ((DNWindowPtr) FrontWindow () == dnWindow) {
  177.                         DoDNWindowOSEvent (theEvent);
  178.                         wasHandled = false;
  179.                     }
  180.                     break;
  181.                     
  182.                 case keyDown:
  183.                 case autoKey:
  184.                     if ((DNWindowPtr) FrontWindow() == dnWindow) {
  185.                         key = theEvent->message & charCodeMask;
  186.                         if ( theEvent->modifiers & cmdKey )    {        // Command key is down
  187.                             wasHandled = false;
  188.                         } else {
  189.                             switch (key) {
  190.                                 case leftArrowKey :
  191.                                 case upArrowKey :
  192.                                     SelectPreviousCell (dnWindow->fCAList);
  193.                                     wasHandled = true;
  194.                                     break;
  195.                                     
  196.                                 case rightArrowKey :
  197.                                 case downArrowKey :
  198.                                     SelectNextCell (dnWindow->fCAList);
  199.                                     wasHandled = true;
  200.                                     break;
  201.                                     
  202.                                 case crKey :
  203.                                 case enterKey :
  204.                                     DisplaySelectedCAs (dnWindow);
  205.                                     wasHandled = true;
  206.                                     break;
  207.                                     
  208.                                 case 'c' :
  209.                                 case 'C' :
  210.                                     DumpSelectedCAInfo (dnWindow);
  211.                                     wasHandled = true;
  212.                                     break;
  213.                                     
  214.                                 case 's' :
  215.                                     DumpSelectedCAState (dnWindow);
  216.                                     wasHandled = true;
  217.                                     break;
  218.                                     
  219.                                 case 'm' :
  220.                                     errCode = TELCAMsgHand (dnWindow->fDNHandle, telCAActiveMsg, gCAActiveMsgHandlerUPP, SetCurrentA5());
  221.                                     if (errCode == noErr)
  222.                                         PutLine (gLogWindow, "gCAActiveMsgHandlerUPP is installed");
  223.                                     else
  224.                                         PutCLine (gLogWindow, kErrorColor, "### TELCAMsgHand fails : %d", errCode);
  225.                                     break;
  226.                                     
  227.                                 case 'M' :
  228.                                     errCode = TELClrCAMsgHand (dnWindow->fDNHandle, gCAActiveMsgHandlerUPP);
  229.                                     if (errCode == noErr)
  230.                                         PutLine (gLogWindow, "gCAActiveMsgHandlerUPP is removed");
  231.                                     else
  232.                                         PutCLine (gLogWindow, kErrorColor, "### TELClrCAMsgHand fails : %d", errCode);
  233.                                     break;
  234.                                 
  235.                                 case 'f' :
  236.                                 case 'F' :
  237.                                     DumpDNFlags (dnWindow->fDNHandle);
  238.                                     break;
  239.                                     
  240.                                 case 'i' :
  241.                                 case 'I' :
  242.                                     DumpDNInfo (dnWindow->fDNHandle);
  243.                                     break;
  244.                                     
  245.                                 case 'e' :
  246.                                 case 'E' :
  247.                                     DumpDNEvents (dnWindow->fDNHandle);
  248.                                     break;
  249.                                     
  250.                                 default :
  251.                                     wasHandled = false;
  252.                             }
  253.                         }
  254.                     }
  255.                     break;
  256.                 
  257.                 default :
  258.                     wasHandled = false;
  259.             }
  260.         }
  261.     }
  262.     
  263.     return (wasHandled);
  264. }
  265.  
  266.  
  267. void    DisposeCAList (DNWindowPtr dnWindow)
  268. {
  269.     /**
  270.      **        Will dispose the list pointed to by fCAList & fCAWindowList
  271.      **        if they are not nil
  272.      **
  273.      **/
  274.      
  275.      CAWindowPtr    tCAWindow1, tCAWindow2;
  276.      
  277.      if (dnWindow->fCAList != nil)
  278.      {
  279.          LDispose (dnWindow->fCAList);
  280.         dnWindow->fCAList = nil;
  281.         
  282.         tCAWindow1 = dnWindow->fCAWindowList;
  283.         while (tCAWindow1 != nil)
  284.         {
  285.             tCAWindow2 = tCAWindow1;
  286.             tCAWindow1 = tCAWindow1->next;
  287.             DisposeCAWindow (tCAWindow2);
  288.         }
  289.         
  290.         dnWindow->fCAWindowList = nil;
  291.      }
  292. }
  293.  
  294.  
  295. Boolean    DoDNWindowMouseDown (const EventRecord *theEvent)
  296. {
  297.     short        part;
  298.     WindowPtr    theWindow;
  299.     Boolean        wasHandled = false;
  300.     
  301.     part = FindWindow(theEvent->where, &theWindow);
  302.     switch ( part ) {            
  303.         case inContent:
  304.             if ( theWindow != FrontWindow() ) {
  305.                 SelectWindow(theWindow);
  306.             } else
  307.                 DoDNWindowClick (theWindow, theEvent);
  308.                 
  309.             wasHandled = true;
  310.             break;        
  311.         
  312.         default :
  313.             wasHandled = false;    
  314.     }
  315.     
  316.     return (wasHandled);
  317. }
  318.  
  319.  
  320. void    DoDNWindowOSEvent (const EventRecord *theEvent)
  321. {
  322.     Boolean doConvert;
  323.     unsigned char evType;
  324.  
  325.     evType = (unsigned char) (theEvent->message >> 24) & 0x00ff; // Get the high byte.
  326.     switch (evType) {                     // The high byte of message is the type of event.
  327.         case suspendResumeMessage :
  328.             doConvert = (theEvent->message & convertClipboardFlag) != 0;
  329.             
  330.             if ((theEvent->message & resumeFlag) == 0)
  331.               DoDNWindowSuspend (doConvert);
  332.               
  333.             else DoDNWindowResume (doConvert);
  334.             break;
  335.     }
  336. }
  337.  
  338.  
  339. void     DoDNWindowSuspend (Boolean doClipConvert)
  340. {
  341. #pragma unused (doClipConvert)
  342.  
  343.     DoDNWindowActivate (FrontWindow(), false);
  344. }
  345.  
  346.  
  347. void     DoDNWindowResume (Boolean doClipConvert)
  348. {
  349. #pragma unused (doClipConvert)
  350.  
  351.     InitCursor ();
  352.     DoDNWindowActivate (FrontWindow(), true);
  353. }
  354.  
  355.  
  356. void    DisplaySelectedCAs (DNWindowPtr dnWindow)
  357. {
  358.     Cell        tCell;
  359.  
  360.     SetPt (&tCell, 0, 0);
  361.     while (LGetSelect (true, &tCell, dnWindow->fCAList)) {
  362.         ShowCAWindow (dnWindow, tCell.v);
  363.         if (! LNextCell (true, true, &tCell, dnWindow->fCAList))
  364.             break;
  365.     }
  366. }
  367.  
  368.  
  369. void    DoDNWindowClick (WindowPtr theWindow, const EventRecord * theEvent)
  370. {
  371.     Point            mousePos;
  372.     WindowPtr        savedPort;
  373.     short            part, value;
  374.     Boolean            dblClicked;
  375.     ControlHandle    theControl;
  376.     
  377.     GetPort    (&savedPort);
  378.     SetPort (theWindow);
  379.     
  380.     mousePos = theEvent->where;
  381.     GlobalToLocal (&mousePos);
  382.  
  383.     if (((DNWindowPtr) theWindow)->fCAList != nil) {
  384.         dblClicked = LClick (mousePos, theEvent->modifiers, ((DNWindowPtr) theWindow)->fCAList);
  385.         
  386.         if (dblClicked == true) {
  387.             DisplaySelectedCAs ((DNWindowPtr) theWindow);
  388.         }
  389.     }
  390.  
  391.     part = FindControl (mousePos, theWindow, &theControl);
  392.     switch (part) {
  393.         case 0 :        // invisible or inactive control was clicked
  394.             break;
  395.         
  396.         case inThumb :
  397.             break;
  398.         
  399.         case inButton :
  400.             part = TrackControl (theControl, mousePos, nil);
  401.             if (part != 0) {
  402.                 switch (GetCRefCon (theControl)) {
  403.                     case rMakeACallCNTL :
  404.                         HandleMakeACall ((DNWindowPtr) theWindow);
  405.                         break;
  406.                         
  407.                     case rIntercomCNTL :
  408.                         HandleIntercom ((DNWindowPtr) theWindow, theEvent->modifiers);
  409.                         break;
  410.                         
  411.                     case rPagingCNTL :
  412.                         HandlePaging ((DNWindowPtr) theWindow, theEvent->modifiers);
  413.                         break;
  414.                         
  415.                     case rCallPickupCNTL :
  416.                         HandleCallPickup ((DNWindowPtr) theWindow, theEvent->modifiers);
  417.                         break;
  418.                         
  419.                     case rVoiceMailCNTL :
  420.                         HandleVoiceMail ((DNWindowPtr) theWindow, theEvent->modifiers);
  421.                         break;
  422.                         
  423.                     case rRetrieveParkCNTL :
  424.                         HandleRetrievePark ((DNWindowPtr) theWindow, theEvent->modifiers);
  425.                         break;
  426.                         
  427.                     case rCallBackNowCNTL :
  428.                         HandleCallBackNow ((DNWindowPtr) theWindow, theEvent->modifiers);
  429.                         break;
  430.                 }
  431.             }
  432.             break;
  433.         
  434.         case inCheckBox:
  435.             part = TrackControl (theControl, mousePos, nil);
  436.             if (part != 0) {
  437.                 value = (GetCtlValue (theControl)) ? false : true;
  438.                 
  439.                 switch (GetCRefCon (theControl)) {
  440.                     case rForwardCNTL :
  441.                         HandleForward ((DNWindowPtr) theWindow, &value);
  442.                         break;
  443.                         
  444.                     case rDNDCNTL :
  445.                         HandleDND ((DNWindowPtr) theWindow, &value);
  446.                         break;
  447.                 }
  448.                 
  449.                 SetCtlValue (theControl, value);
  450.             }
  451.             break;
  452.     }
  453.     
  454.     SetPort (savedPort);
  455. }
  456.  
  457.  
  458. void    DoDNWindowActivate (WindowPtr theWindow, Boolean becomingActive)
  459. {
  460.     WindowPtr        savedPort;
  461.     ControlHandle    theControl;
  462.     
  463.     GetPort (&savedPort);
  464.     SetPort (theWindow);
  465.     
  466.     theControl = ((WindowPeek) theWindow)->controlList;
  467.     while (theControl != nil) {
  468.         HiliteControl (theControl, (becomingActive)?0:255);
  469.         theControl = (*theControl)->nextControl;
  470.     }
  471.     
  472.     if (((DNWindowPtr) theWindow)->fCAList != nil)
  473.         LActivate (becomingActive, ((DNWindowPtr) theWindow)->fCAList);
  474.  
  475.     SetPort (savedPort);
  476. }
  477.  
  478.  
  479. void    DoDNWindowUpdate (WindowPtr theWindow)
  480. {
  481.     WindowPtr    savedPort;
  482.     Rect        tRect;
  483.  
  484.     BeginUpdate (theWindow);    
  485.     if ( ! EmptyRgn (theWindow->visRgn) )
  486.     {
  487.         GetPort (&savedPort);
  488.         SetPort (theWindow);
  489.         
  490. //        EraseRect(&theWindow->portRect);
  491.         UpdtControl (theWindow, theWindow->visRgn);
  492.         
  493.         if (((DNWindowPtr) theWindow)->fCAList != nil) {
  494.             LUpdate (theWindow->visRgn, ((DNWindowPtr) theWindow)->fCAList);
  495.             
  496.             tRect = (*((DNWindowPtr) theWindow)->fCAList)->rView;
  497.             InsetRect (&tRect, -1, -1);
  498.             FrameRect (&tRect);
  499.         }
  500.         SetPort (savedPort);
  501.     }
  502.     EndUpdate (theWindow);
  503. }
  504.  
  505.  
  506. OSErr    CreateCAList (DNWindowPtr dnWindow)
  507. {
  508.     /**
  509.      **        This routine will create a list of CAs using the list manager.
  510.      **        If successful, it will call CreateCAWindowList to build the
  511.      **        list of CA windows.
  512.      **
  513.      **/
  514.      
  515.     Rect        rView, dataBounds;
  516.     Point        cSize;
  517.     Rect        **rectHandle;
  518.     WindowPtr    savedPort;
  519.     
  520.     SetRect (&dataBounds, 0, 0, 1, 0);            // one-column list
  521.     
  522.     SetPt (&cSize, 0, 0);                        // use default cell size
  523.  
  524.     rectHandle = (Rect **) Get1Resource ('RECT', rCAListRECT);
  525.     if (rectHandle) {
  526.         rView = **rectHandle;
  527.         rView.right -= 15;
  528.         ReleaseResource ((Handle) rectHandle);
  529.     } else {
  530.         rView = ((WindowPtr) dnWindow)->portRect;
  531.         rView.right -= 15;
  532.     }
  533.     
  534.     if ((dnWindow->fCAList = lnew (&rView, &dataBounds, &cSize, 0, (WindowPtr)dnWindow,
  535.             true, false, false, true)) != nil) {
  536.         
  537.         LActivate (false, dnWindow->fCAList);
  538.         
  539.         GetPort (&savedPort);
  540.         SetPort ((WindowPtr) dnWindow);
  541.         InvalRect (&rView);
  542.         SetPort (savedPort);
  543.         
  544. #ifdef DEBUGNOCARD
  545.         return (DummyCreateCAWindowList (dnWindow));
  546. #else
  547.         return (CreateCAWindowList (dnWindow));
  548. #endif  /* DEBUGNOCARD */
  549.     }
  550.     else
  551.         return (MemError());
  552. }
  553.  
  554.  
  555. #ifdef DEBUGNOCARD
  556. OSErr    DummyCreateCAWindowList (DNWindowPtr dnWindow)
  557. {
  558.     OSErr                errCode = noErr;
  559.     short                numOfCAs, index;
  560.     TELCAHandle    caHand = nil;
  561.     CAWindowPtr            *tCAWindow;
  562.     Cell                tCell;
  563.     char                *ca[1];
  564.     
  565.     ca[0] = "ca#1";
  566.     
  567.     tCAWindow = &dnWindow->fCAWindowList;
  568.     
  569.     numOfCAs = 1;
  570.     
  571.     for (index = 1; index <= numOfCAs; ++index) {
  572.         *tCAWindow = CreateCAWindow (caHand, ca[index-1]);
  573.         (*caHand)->refCon = (long) dnWindow;
  574.         if (*tCAWindow != nil) {
  575.             tCAWindow = &(*tCAWindow)->next;
  576.             
  577.             SetPt (&tCell, 0, index-1);
  578.             LAddRow (1, index-1, dnWindow->fCAList);
  579.             LSetCell (ca[index-1], 4, tCell, dnWindow->fCAList);
  580.         }
  581.         else
  582.             PutCLine (gLogWindow, kErrorColor, "### CreateCAWindow fails");
  583.     }
  584.     
  585.     if (numOfCAs > 0) {                                // hilite the first row & column
  586.         SetPt (&tCell, 0, 0);                        
  587.         LSetSelect (true, tCell, dnWindow->fCAList);
  588.     }
  589.     
  590.     return (errCode);
  591. }
  592. #endif  /* DEBUGNOCARD */
  593.  
  594.  
  595. OSErr    CreateCAWindowList (DNWindowPtr dnWindow)
  596. {
  597.     OSErr        errCode;
  598.     short        numOfCAs = 0, index;
  599.     TELDNHandle    dnHand;
  600.     TELCAHandle    caHand;
  601.     CAWindowPtr    *tCAWindow;
  602.     Cell        tCell;
  603.     Str31         title;
  604.  
  605.     dnHand = dnWindow->fDNHandle;
  606.     tCAWindow = &dnWindow->fCAWindowList;
  607.     
  608.     if (dnHand != nil) {
  609.  
  610.         (void) TELGetDNInfo (dnHand);
  611.  
  612.         numOfCAs = TELCountCAs (dnHand, telAllCallOrigins);
  613.         
  614.         for (index = 1; index <= numOfCAs; ++index) {
  615.             errCode = TELCALookup (dnHand, telAllCallOrigins, index, &caHand);
  616.             if (errCode == noErr) {
  617.                 sprintf ((char *) title, "caHand = 0x%x", caHand);
  618.                 *tCAWindow = CreateCAWindow (caHand, (char *) title);
  619.                 (*caHand)->refCon = (long) dnWindow;
  620.                 if (*tCAWindow != nil) {
  621.                     tCAWindow = &(*tCAWindow)->next;
  622.                     
  623.                     SetPt (&tCell, 0, index-1);
  624.                     LAddRow (1, index-1, dnWindow->fCAList);
  625.  
  626.                     UpdateCAListState (dnWindow, caHand);
  627.                 }
  628.                 else
  629.                     if ((errCode = TELCADispose (caHand)) != noErr)
  630.                         PutCLine (gLogWindow, kErrorColor, "### TELCADispose failed : %d", errCode);
  631.             }
  632.             else
  633.                 PutCLine (gLogWindow, kErrorColor, "### TELCALookup fails : %d", errCode);
  634.         }
  635.     }
  636.     else
  637.         PutCLine (gLogWindow, kErrorColor, "### Invalid dnHand");
  638.     
  639.     if (numOfCAs > 0) {                                // hilite the first row & column
  640.         SetPt (&tCell, 0, 0);                        
  641.         LSetSelect (true, tCell, dnWindow->fCAList);
  642.     }
  643.     
  644.     return (errCode);
  645. }
  646.  
  647.  
  648. DNWindowPtr    CreateDNWindow (TELDNHandle dnHand, char * title)
  649. {
  650.     DNWindowPtr    dnWindow;
  651.     WindowPtr    savedPort;
  652.     Ptr            tPtr;
  653.      
  654.     tPtr = NewPtrClear (sizeof (DNWindowRec));
  655.     if (tPtr == nil) {
  656.         AlertUser ("\pNot enough memory to create dn window !", MemError ());
  657.         return (nil);
  658.     }
  659.     
  660.     if (HasColorQD ())
  661.         dnWindow = (DNWindowPtr) GetNewCWindow (rDNWIND, tPtr, (WindowPtr)(-1L));
  662.     else
  663.         dnWindow = (DNWindowPtr) GetNewWindow (rDNWIND, tPtr, (WindowPtr)(-1L));
  664.         
  665.     if (dnWindow == nil) {
  666.         AlertUser ("\pUnable to get a WIND resource for dn window!", ResError ());
  667.         DisposPtr (tPtr);
  668.         return (nil);
  669.     }
  670.     
  671.     dnWindow->fForwardAttrib = (ForwardAttribHandle) NewHandleClear (sizeof(ForwardAttrib));
  672.     if (dnWindow->fForwardAttrib == nil) {
  673.         AlertUser ("\pNot enough memory to create dn window !", MemError ());
  674.         DisposeWindow ((WindowPtr) dnWindow);
  675.         return (nil);
  676.     }
  677.     (*dnWindow->fForwardAttrib)->fwdType = telForwardImmediate;
  678.         
  679.     dnWindow->fDNDAttrib = (DNDAttribHandle) NewHandleClear (sizeof(DNDAttrib));
  680.     if (dnWindow->fDNDAttrib == nil) {
  681.         AlertUser ("\pNot enough memory to create dn window !", MemError ());
  682.         DisposeWindow ((WindowPtr) dnWindow);
  683.         return (nil);
  684.     }
  685.         
  686.     dnWindow->fCallPickupAttrib = (CallPickupAttribHandle) NewHandleClear (sizeof(CallPickupAttrib));
  687.     if (dnWindow->fCallPickupAttrib == nil) {
  688.         AlertUser ("\pNot enough memory to create dn window !", MemError ());
  689.         DisposeWindow ((WindowPtr) dnWindow);
  690.         return (nil);
  691.     }
  692.         
  693.     dnWindow->fMakeACallAttrib = (MakeACallAttribHandle) NewHandleClear (sizeof(MakeACallAttrib));
  694.     if (dnWindow->fMakeACallAttrib == nil) {
  695.         AlertUser ("\pNot enough memory to create dn window !", MemError ());
  696.         DisposeWindow ((WindowPtr) dnWindow);
  697.         return (nil);
  698.     }
  699.         
  700.     /**
  701.      **        Set the window's characteristics.
  702.      **
  703.      **/
  704.      
  705.     GetPort (&savedPort);
  706.     SetPort ((WindowPtr) dnWindow);
  707.     TextSize (9);
  708.     SetPort (savedPort);
  709.     
  710.     setwtitle ((WindowPtr) dnWindow, title);
  711.     
  712.     AttachDNWindowControls (dnWindow, dnHand);
  713.     
  714.     dnWindow->fDNHandle = dnHand;
  715.     (void) InstallDNHandler (dnHand);
  716.     (void) InstallCAHandler (dnHand);
  717.                 
  718.     if (CreateCAList (dnWindow) == nil) {}
  719.     
  720.     (*dnHand)->userData = (long) dnWindow;    // so we can find the corresponding dnwindow if given a dnHand
  721.     
  722.     ShowWindow ((WindowPtr) dnWindow);
  723.  
  724.     return (dnWindow);
  725. }
  726.  
  727.  
  728. void    DisposeDNWindow (DNWindowPtr dnWindow)
  729. {
  730.     OSErr        errCode;
  731.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  732.     CAWindowPtr    caWindow, tCAWindow;
  733.     
  734.     if (dnWindow != nil) {
  735.         if (dnWindow->fCAList != nil)
  736.             LDispose (dnWindow->fCAList);
  737.         
  738.         caWindow = dnWindow->fCAWindowList;
  739.         while (tCAWindow = caWindow) {
  740.             caWindow = caWindow->next;
  741.             DisposeCAWindow (tCAWindow);
  742.         }
  743.         
  744.         if (dnWindow->fForwardAttrib)
  745.             DisposHandle ((Handle) dnWindow->fForwardAttrib);
  746.         if (dnWindow->fDNDAttrib)
  747.             DisposHandle ((Handle) dnWindow->fDNDAttrib);
  748.         if (dnWindow->fCallPickupAttrib)
  749.             DisposHandle ((Handle) dnWindow->fCallPickupAttrib);
  750.         if (dnWindow->fMakeACallAttrib)
  751.             DisposHandle ((Handle) dnWindow->fMakeACallAttrib);
  752.     
  753.         if (dnHand) {
  754.             if ((errCode = TELClrDNMsgHand (dnHand, gDNMsgHandlerUPP)) != noErr)
  755.                 PutCLine (gLogWindow, kErrorColor, "### TELClrDNMsgHand fails : %d", errCode);
  756.                 
  757.             if ((errCode = TELClrCAMsgHand (dnHand, gCAMsgHandlerUPP)) != noErr)
  758.                 PutCLine (gLogWindow, kErrorColor, "### TELClrCAMsgHand fails : %d", errCode);
  759.  
  760.             if ((errCode = TELDNDispose (dnHand)) != noErr)
  761.                 PutCLine (gLogWindow, kErrorColor, "### TELDNDispose failed : %d", errCode);    
  762.         }
  763.     
  764.         DisposeWindow ((WindowPtr) dnWindow);
  765.     }
  766. }
  767.  
  768.  
  769. void    AttachDNWindowControls (DNWindowPtr dnWindow, TELDNHandle dnHand)
  770. {
  771.     Boolean            fwdActive;
  772.     long            forwardFlags;
  773.     OSErr            errCode;
  774.     WindowPtr        savedPort;
  775.     ControlHandle    theControl;
  776. //    Rect            boundsRect;
  777.     
  778.     GetPort (&savedPort);
  779.     SetPort ((WindowPtr) dnWindow);
  780.     
  781.     dnWindow->fMakeACall     = GetNewControl (rMakeACallCNTL, (WindowPtr) dnWindow);
  782.     dnWindow->fIntercom        = GetNewControl (rIntercomCNTL, (WindowPtr) dnWindow);
  783.     dnWindow->fPaging         = GetNewControl (rPagingCNTL, (WindowPtr) dnWindow);
  784.     dnWindow->fCallPickup    = GetNewControl (rCallPickupCNTL, (WindowPtr) dnWindow);
  785.     dnWindow->fVoiceMail    = GetNewControl (rVoiceMailCNTL, (WindowPtr) dnWindow);
  786.     dnWindow->fRetrievePark    = GetNewControl (rRetrieveParkCNTL, (WindowPtr) dnWindow);
  787.     (void) GetNewControl (rCallBackNowCNTL, (WindowPtr) dnWindow);
  788.     dnWindow->fForward        = GetNewControl (rForwardCNTL, (WindowPtr) dnWindow);
  789.     dnWindow->fDND            = GetNewControl (rDNDCNTL, (WindowPtr) dnWindow);
  790.     
  791.     dnWindow->fDirNumber    = GetNewControl (rDirNumberCNTL, (WindowPtr) dnWindow);
  792.     
  793.     if ((errCode = TELGetDNInfo (dnHand)) != noErr)
  794.         PutCLine (gLogWindow, kErrorColor, "### TELDNGetInfo fails : %d", errCode);
  795.     
  796.     SetCtlValue (dnWindow->fDND, ((*dnHand)->featureFlags & dndActive));
  797.     
  798.     forwardFlags = (*dnHand)->forwardFlags;
  799.     fwdActive = (forwardFlags  & immediateForwardActive) || (forwardFlags  & busyForwardActive) || 
  800.                     (forwardFlags  & noAnswerForwardActive) || (forwardFlags  & busyNAForwardActive);
  801.     SetCtlValue (dnWindow->fForward, fwdActive);
  802.     
  803.     SetControlTitle (dnWindow->fDirNumber, (*dnHand)->dn);
  804.         
  805.     theControl = ((WindowPeek) dnWindow)->controlList;
  806.     while (theControl != nil) {
  807.         HiliteControl (theControl, 0xFF);
  808.         theControl = (*theControl)->nextControl;
  809.     }
  810.     
  811.     SetPort (savedPort);
  812. }
  813.  
  814.  
  815. void    PrepareForwardDLOGUserItems (DialogPtr    theDialog)
  816. {
  817.     short    itemType;
  818.     Handle    item;
  819.     Rect    box;
  820.     CursHandle     watch = GetCursor(watchCursor);
  821.     
  822.     if (watch != nil)
  823.         SetCursor (*watch);
  824.     
  825.     GetDItem (theDialog, kForwardBox1, &itemType, &item, &box);
  826.     SetDItem (theDialog, kForwardBox1, itemType, (Handle) gDrawBoxUPP, &box);
  827.     
  828.     GetDItem (theDialog, kForwardBox2, &itemType, &item, &box);
  829.     SetDItem (theDialog, kForwardBox2, itemType, (Handle) gDrawBoxUPP, &box);
  830.     
  831.     GetDItem (theDialog, kForwardBox3, &itemType, &item, &box);
  832.     SetDItem (theDialog, kForwardBox3, itemType, (Handle) gDrawBoxUPP, &box);
  833.     
  834.     GetDItem (theDialog, kForwardDefault, &itemType, &item, &box);
  835.     SetDItem (theDialog, kForwardDefault, itemType, (Handle) gDrawDefaultUPP, &box);
  836.     
  837.     if (watch != nil)
  838.         ReleaseResource ((Handle) watch);
  839.     
  840.     SetCursor (&qd.arrow);
  841. }
  842.  
  843.  
  844. short    DisplayForwardDialog (DNWindowPtr dnWindow)
  845. {
  846.     DialogPtr    theDialog;
  847.     short        itemHit;
  848.     short        returnValue;
  849.     ForwardAttribHandle    theForwardAttrib = dnWindow->fForwardAttrib;
  850.     
  851.     theDialog = GetNewDialog (rForwardDLOG, nil, (WindowPtr)(-1L));
  852.     if (theDialog == nil) {
  853.         AlertUser ("\pUnable to get a DLOG resource !", ResError());
  854.         return (-1);
  855.     }
  856.     
  857.     PrepareForwardDLOGUserItems (theDialog);
  858.     PutForwardAttribToDialog (theDialog, theForwardAttrib);
  859.  
  860.     ShowWindow (theDialog);
  861.     
  862.     ModalDialog (gStandardFilterUPP, &itemHit);    
  863.         
  864.     HideWindow (theDialog);
  865.     
  866.     switch (itemHit) {
  867.         case ok :
  868.             PutDialogSetupToForwardAttrib (theDialog, theForwardAttrib);
  869.             if ((returnValue = SetForwarding (dnWindow)) == noErr)
  870.                 returnValue = ok;
  871.                 
  872.             break;
  873.         
  874.         default :
  875.             returnValue = cancel;
  876.     }
  877.     
  878.     DisposDialog (theDialog);
  879.     
  880.     return (returnValue);
  881. }
  882.  
  883.  
  884. void    PutForwardAttribToDialog (DialogPtr theDialog, ForwardAttribHandle theForwardAttrib)
  885. {
  886.     short    itemKind;
  887.     Handle    itemHand;
  888.     Rect    itemRect;
  889.     Str255    tStr;
  890.     
  891.     GetDItem (theDialog, kForwardNumber, &itemKind, &itemHand, &itemRect);
  892.     SetIText (itemHand, (**theForwardAttrib).dn);
  893.     SelIText (theDialog, kForwardNumber, 0, 32767);
  894.  
  895.     GetDItem (theDialog, kForwardName, &itemKind, &itemHand, &itemRect);
  896.     SetIText (itemHand, (**theForwardAttrib).name);
  897.  
  898.     GetDItem (theDialog, kForwardSubAddr, &itemKind, &itemHand, &itemRect);
  899.     SetIText (itemHand, (**theForwardAttrib).subAddr);
  900.  
  901.     GetDItem (theDialog, kForwardNumRings, &itemKind, &itemHand, &itemRect);
  902.     NumToString ((**theForwardAttrib).numOfRings, tStr);
  903.     SetIText (itemHand, tStr);
  904.  
  905.     GetDItem (theDialog, kForwardPopup, &itemKind, &itemHand, &itemRect);
  906.     SetCtlValue ((ControlHandle) itemHand, (**theForwardAttrib).fwdType);
  907. }
  908.  
  909.  
  910. void    PutDialogSetupToForwardAttrib (DialogPtr theDialog, ForwardAttribHandle theForwardAttrib)
  911. {
  912.     short    itemKind;
  913.     Handle    itemHand;
  914.     Rect    itemRect;
  915.     Str255    tStr;
  916.     long    tlong;
  917.     
  918.     GetDItem (theDialog, kForwardNumber, &itemKind, &itemHand, &itemRect);
  919.     GetIText (itemHand, (**theForwardAttrib).dn);
  920.  
  921.     GetDItem (theDialog, kForwardName, &itemKind, &itemHand, &itemRect);
  922.     GetIText (itemHand, (**theForwardAttrib).name);
  923.  
  924.     GetDItem (theDialog, kForwardSubAddr, &itemKind, &itemHand, &itemRect);
  925.     GetIText (itemHand, (**theForwardAttrib).subAddr);
  926.  
  927.     GetDItem (theDialog, kForwardNumRings, &itemKind, &itemHand, &itemRect);
  928.     GetIText (itemHand, tStr);
  929.     StringToNum (tStr, &tlong);
  930.     (**theForwardAttrib).numOfRings = tlong;
  931.     
  932.     GetDItem (theDialog, kForwardPopup, &itemKind, &itemHand, &itemRect);
  933.     (**theForwardAttrib).fwdType = GetCtlValue ((ControlHandle) itemHand);
  934. }
  935.  
  936.  
  937. OSErr    SetForwarding (DNWindowPtr dnWindow)
  938. {
  939.     OSErr    errCode = noErr;
  940.     ForwardAttribHandle    tForwardAttrib = dnWindow->fForwardAttrib;
  941.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  942.  
  943.     if (dnHand) {    
  944.         errCode = TELForwardSet (dnHand, (*tForwardAttrib)->dn, 
  945.                     (*tForwardAttrib)->name, 
  946.                     (*tForwardAttrib)->subAddr, 
  947.                     (*tForwardAttrib)->fwdType, (*tForwardAttrib)->numOfRings);
  948.     
  949.         if (errCode == noErr)
  950.             PutLine (gLogWindow, "Forwarding is set successfully");
  951.         else
  952.             PutCLine (gLogWindow, kErrorColor, "### TELForwardSet fails : %d", errCode);
  953.     }
  954.     
  955.     return (errCode);
  956. }
  957.  
  958.  
  959. OSErr    CancelForwarding (DNWindowPtr dnWindow)
  960. {
  961.     OSErr                errCode = noErr;
  962.     ForwardAttribHandle    tForwardAttrib = dnWindow->fForwardAttrib;
  963.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  964.     
  965.     if (dnHand) {
  966.         errCode = TELForwardClear (dnHand, (*tForwardAttrib)->fwdType);
  967.         
  968.         if (errCode == noErr)
  969.             PutLine (gLogWindow, "Forwarding is canceled successfully");
  970.         else
  971.             PutCLine (gLogWindow, kErrorColor, "### TELForwardClear fails : %d", errCode);
  972.     }
  973.     
  974.     return (errCode);
  975. }
  976.  
  977.  
  978. void    HandleForward (DNWindowPtr dnWindow, short * value)
  979. {
  980.     if (*value) {
  981.         if (DisplayForwardDialog (dnWindow) == ok)
  982.             *value = true;
  983.         else
  984.             *value = false;
  985.     }
  986.     else
  987.         (void) CancelForwarding (dnWindow);
  988. }
  989.  
  990.  
  991. void    HandleDND (DNWindowPtr dnWindow, short * value)
  992. {
  993.     if (*value) {
  994.         if (DisplayDNDDialog (dnWindow) == ok)
  995.             *value = true;
  996.         else
  997.             *value = false;
  998.     }
  999.     else
  1000.         (void) CancelDND (dnWindow);
  1001. }
  1002.  
  1003.  
  1004. void    HandleMakeACall (DNWindowPtr dnWindow)
  1005. {
  1006.     OSErr                errCode;
  1007.     TELCAHandle    caHand;
  1008.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  1009.     MakeACallAttribHandle    tMakeACallAttrib = dnWindow->fMakeACallAttrib;
  1010.     
  1011.     if (dnHand) {
  1012.         if (DisplayMakeACallDialog (dnWindow) == ok) {
  1013.             errCode = TELSetupCall (dnHand, &caHand, 
  1014.                         (*tMakeACallAttrib)->destDN, 
  1015.                         (*tMakeACallAttrib)->destName, 
  1016.                         (*tMakeACallAttrib)->subAddr,
  1017.                         (*tMakeACallAttrib)->userUserInfo, 
  1018.                         (*tMakeACallAttrib)->bearerType, 
  1019.                         (*tMakeACallAttrib)->rate);
  1020.             if (errCode == noErr) {
  1021.                 PutLine (gLogWindow, "TELSetupCall (%08x)", caHand);
  1022.                 
  1023.                 AppendCAList (dnWindow, caHand);
  1024.                 
  1025.                 errCode = TELConnect (caHand);
  1026.                 if (errCode != noErr)
  1027.                     PutCLine (gLogWindow, kErrorColor, "### TELConnect fails : %d", errCode);
  1028.                 else
  1029.                     PutLine (gLogWindow, "TELConnect (%08x)", caHand);
  1030.             }
  1031.             else
  1032.                 PutCLine (gLogWindow, kErrorColor, "### TELSetupCall fails : %d", errCode);
  1033.         }
  1034.     }
  1035. }
  1036.  
  1037.  
  1038. TELCAHandle    SetUpACall (DNWindowPtr dnWindow)
  1039. {
  1040.     OSErr                    errCode;
  1041.     TELCAHandle        caHand = nil;
  1042.     TELDNHandle        dnHand = dnWindow->fDNHandle;
  1043.     MakeACallAttribHandle    tMakeACallAttrib = dnWindow->fMakeACallAttrib;
  1044.     
  1045.     if (dnHand) {
  1046.         if (DisplayMakeACallDialog (dnWindow) == ok) {
  1047.             errCode = TELSetupCall (dnHand, &caHand, 
  1048.                         (*tMakeACallAttrib)->destDN, 
  1049.                         (*tMakeACallAttrib)->destName, 
  1050.                         (*tMakeACallAttrib)->subAddr,
  1051.                         (*tMakeACallAttrib)->userUserInfo, 
  1052.                         (*tMakeACallAttrib)->bearerType, 
  1053.                         (*tMakeACallAttrib)->rate);
  1054.             if (errCode == noErr) {
  1055.                 PutLine (gLogWindow, "TELSetupCall (%08x)", caHand);
  1056.                 AppendCAList (dnWindow, caHand);
  1057.             }
  1058.             else
  1059.                 PutCLine (gLogWindow, kErrorColor, "### TELSetupCall fails : %d", errCode);
  1060.         }
  1061.     }
  1062.     
  1063.     return (caHand);
  1064. }
  1065.  
  1066.  
  1067. short    GetANumber (void)
  1068. {
  1069.     DialogPtr    theDialog;
  1070.     short        itemHit;
  1071.     short        returnValue = 0;
  1072.     short        itemKind;
  1073.     Handle        itemHand;
  1074.     Rect        itemRect;
  1075.     long        tlong;
  1076.     Str255        tStr;
  1077.     
  1078.     theDialog = GetNewDialog (rGetANumberDLOG, nil, (WindowPtr)(-1L));
  1079.     if (theDialog == nil) {
  1080.         AlertUser ("\pUnable to get a DLOG resource !", ResError());
  1081.         return (0);
  1082.     }
  1083.     
  1084.     GetDItem (theDialog, kGetANumberNumber, &itemKind, &itemHand, &itemRect);
  1085.     SelIText (theDialog, kGetANumberNumber, 0, 32767);
  1086.  
  1087.     ShowWindow (theDialog);
  1088.     
  1089.     ModalDialog (nil, &itemHit);    
  1090.         
  1091.     HideWindow (theDialog);
  1092.     
  1093.     switch (itemHit) {
  1094.         case ok :
  1095.             GetDItem (theDialog, kGetANumberNumber, &itemKind, &itemHand, &itemRect);
  1096.             GetIText (itemHand, tStr);
  1097.             StringToNum (tStr, &tlong);
  1098.             returnValue = tlong;                
  1099.             break;
  1100.     }
  1101.     
  1102.     DisposDialog (theDialog);
  1103.     
  1104.     return (returnValue);
  1105. }
  1106.  
  1107.  
  1108. TELCAHandle    GetAvailableCA (void)
  1109. {
  1110.     short    state;
  1111.     OSErr    errCode;
  1112.     
  1113.     if (gAvailableCA) {
  1114.         if ((errCode = TELGetCAState (gAvailableCA, &state)) == noErr) {
  1115.             if (state != telCADialToneState)
  1116.                 gAvailableCA = nil;
  1117.         }
  1118.         else {
  1119.             PutCLine (gLogWindow, kErrorColor, "### TELGetCAState fails : %d", errCode);
  1120.             gAvailableCA = nil;
  1121.         }
  1122.     }
  1123.     
  1124.     return (gAvailableCA);
  1125. }
  1126.  
  1127.  
  1128. TELCAHandle    GetFreeCAHandle (DNWindowPtr dnWindow, short getNewCA)
  1129. {
  1130.     OSErr        errCode;
  1131.     TELCAHandle    caHand = nil;
  1132.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  1133.     short        bearerType = 0, rate = 0;
  1134.     
  1135.     if (! getNewCA)
  1136.         caHand = GetAvailableCA ();
  1137.     
  1138.     if (caHand == nil)    // either user wants a new ca or the avail ca is not in dialtone state
  1139.         if (dnHand) {
  1140.             errCode = TELSetupCall (dnHand, &caHand, "\p", "\p", "\p", "\p", bearerType, rate);
  1141.     
  1142.             if (errCode != noErr) {
  1143.                 caHand = nil;
  1144.                 PutCLine (gLogWindow, kErrorColor, "### TELSetupCall fails : %d", errCode);
  1145.             }
  1146.             else {
  1147.                 PutLine (gLogWindow, "TELSetupCall (%08x)", caHand);
  1148.                 AppendCAList (dnWindow, caHand);
  1149.             }
  1150.         }
  1151.     
  1152.     return (caHand);
  1153. }
  1154.  
  1155.  
  1156. void    HandleIntercom (DNWindowPtr dnWindow, short modifiers)
  1157. {
  1158.     OSErr        errCode = noErr;
  1159.     TELCAHandle    caHand = nil;
  1160.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  1161.     short        intercomID;
  1162.     
  1163.     if (dnHand) {
  1164.         intercomID = (*dnHand)->numIntercomIDs;
  1165.         if (intercomID > 0) {
  1166.             PutLine (gLogWindow, "NumIntercomIDs = %d", intercomID);
  1167.             intercomID = GetANumber ();
  1168.         }
  1169.         
  1170.         if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
  1171.                 
  1172.             errCode = TELIntercom (caHand, intercomID);
  1173.             
  1174.             if (errCode == noErr)
  1175.                 PutLine (gLogWindow, "TELInterCom (%08x)", caHand);
  1176.             else {
  1177.                 PutCLine (gLogWindow, kErrorColor, "### TELIntercom fails : %d", errCode);
  1178.                 
  1179.                 RemoveFromCAList (dnWindow, caHand);
  1180.             }
  1181.         }
  1182.     }
  1183. }
  1184.  
  1185.  
  1186. void    HandlePaging (DNWindowPtr dnWindow, short modifiers)
  1187. {
  1188.     OSErr                errCode = noErr;
  1189.     TELCAHandle    caHand = nil;
  1190.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  1191.     short                pageID;
  1192.     
  1193.     if (dnHand) {
  1194.         pageID = (*dnHand)->numPageIDs;
  1195.         if (pageID > 0) {
  1196.             PutLine (gLogWindow, "NumPageIDs = %d", pageID);
  1197.             pageID = GetANumber ();
  1198.         }
  1199.         
  1200.         if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
  1201.             errCode = TELPaging (caHand, pageID);
  1202.             
  1203.             if (errCode == noErr)
  1204.                 PutLine (gLogWindow, "TELPaging (%08x)", caHand);
  1205.             else {
  1206.                 PutCLine (gLogWindow, kErrorColor, "### TELPaging fails : %d", errCode);
  1207.                 
  1208.                 RemoveFromCAList (dnWindow, caHand);
  1209.             }
  1210.         }
  1211.     }
  1212. }
  1213.  
  1214.  
  1215. void    HandleCallPickup (DNWindowPtr dnWindow, short modifiers)
  1216. {
  1217.     OSErr                    errCode = noErr;
  1218.     CallPickupAttribHandle    tCallPickupAttrib = dnWindow->fCallPickupAttrib;
  1219.     TELCAHandle        caHand = nil;
  1220.     TELDNHandle        dnHand = dnWindow->fDNHandle;
  1221.     short                    pickupIDs;
  1222.     
  1223.     if (dnHand) {
  1224.         pickupIDs = (*dnHand)->numPickupIDs;
  1225.         if (pickupIDs > 0)
  1226.             PutLine (gLogWindow, "NumPickupIDs = %d", pickupIDs);
  1227.  
  1228.         if (DisplayCallPickupDialog (dnWindow) == ok) {
  1229.             if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
  1230.                 errCode = TELCallPickup (caHand, (*tCallPickupAttrib)->pickupDN,
  1231.                                 (*tCallPickupAttrib)->pickupGroupID);
  1232.                 
  1233.                 if (errCode == noErr)
  1234.                     PutLine (gLogWindow, "TELCallPickup is called successfully");
  1235.                 else {
  1236.                     PutCLine (gLogWindow, kErrorColor, "### TELCallPickup fails : %d", errCode);
  1237.                     
  1238.                     RemoveFromCAList (dnWindow, caHand);
  1239.                 }
  1240.             }
  1241.         }
  1242.     }
  1243. }
  1244.  
  1245.  
  1246. void    HandleVoiceMail (DNWindowPtr dnWindow, short modifiers)
  1247. {
  1248.     OSErr                errCode = noErr;
  1249.     TELCAHandle    caHand = nil;
  1250.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  1251.  
  1252.     if (dnHand) {    
  1253.         if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
  1254.             errCode = TELVoiceMailAccess (caHand);
  1255.             
  1256.             if (errCode == noErr)
  1257.                 PutLine (gLogWindow, "TELVoiceMailAccess (%08x)", caHand);
  1258.             else {
  1259.                 PutCLine (gLogWindow, kErrorColor, "### TELVoiceMailAccess fails : %d", errCode);
  1260.                 
  1261.                 RemoveFromCAList (dnWindow, caHand);
  1262.             }
  1263.         }
  1264.     }
  1265. }
  1266.  
  1267.  
  1268. void    HandleRetrievePark (DNWindowPtr dnWindow, short modifiers)
  1269. {
  1270.     OSErr                errCode = noErr;
  1271.     TELCAHandle    caHand = nil;
  1272.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  1273.     Str255                parkID;
  1274.     long                caFeatureFlags, caOtherFeatures;
  1275.  
  1276.     if (dnHand) {                    
  1277.         if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
  1278.             if ((errCode = TELGetCAFlags (caHand, &caFeatureFlags, &caOtherFeatures)) == noErr) {
  1279.                 if (caOtherFeatures & parkRetrieveWithID)
  1280.                     if (DisplayGetParkIDDialog (parkID) != ok) {
  1281.                         RemoveFromCAList (dnWindow, caHand);
  1282.                         return;
  1283.                     }
  1284.  
  1285.                 errCode = TELRetrieveParkedCall (caHand, parkID);
  1286.                 
  1287.                 if (errCode == noErr)
  1288.                     PutLine (gLogWindow, "TELRetrieveParkedCall (%08x)", caHand);
  1289.                 else {
  1290.                     PutCLine (gLogWindow, kErrorColor, "### TELRetrieveParkedCall fails : %d", errCode);
  1291.                     
  1292.                     RemoveFromCAList (dnWindow, caHand);
  1293.                 }
  1294.             }
  1295.             else
  1296.                 PutCLine (gLogWindow, kErrorColor, "### TELGetCAFlags fails : %d", errCode);
  1297.         }
  1298.     }
  1299. }
  1300.  
  1301.  
  1302. void    HandleCallBackNow (DNWindowPtr dnWindow, short modifiers)
  1303. {
  1304.     OSErr        errCode = noErr;
  1305.     TELCAHandle    caHand = nil;
  1306.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  1307.     short        cbRef = 0;
  1308.  
  1309.     if (dnHand) {    
  1310.         if ((caHand = GetFreeCAHandle (dnWindow, modifiers & optionKey)) != nil) {
  1311.             errCode = TELCallbackNow (caHand, cbRef);
  1312.             
  1313.             if (errCode == noErr)
  1314.                 PutLine (gLogWindow, "TELCallbackNow (%08x) -> cbRef = %d", caHand, cbRef);
  1315.             else {
  1316.                 PutCLine (gLogWindow, kErrorColor, "### TELCallbackNow fails : %d", errCode);
  1317.                 
  1318.                 RemoveFromCAList (dnWindow, caHand);
  1319.             }
  1320.         }
  1321.     }
  1322. }
  1323.  
  1324.  
  1325. void    PrepareDNDDLOGUserItems (DialogPtr theDialog)
  1326. {
  1327.     short    itemType;
  1328.     Handle    item;
  1329.     Rect    box;
  1330.     CursHandle     watch = GetCursor(watchCursor);
  1331.     
  1332.     if (watch != nil)
  1333.         SetCursor (*watch);
  1334.     
  1335.     GetDItem (theDialog, kDNDBox1, &itemType, &item, &box);
  1336.     SetDItem (theDialog, kDNDBox1, itemType, (Handle) gDrawBoxUPP, &box);
  1337.     
  1338.     GetDItem (theDialog, kDNDDefault, &itemType, &item, &box);
  1339.     SetDItem (theDialog, kDNDDefault, itemType, (Handle) gDrawDefaultUPP, &box);
  1340.     
  1341.     if (watch != nil)
  1342.         ReleaseResource ((Handle) watch);
  1343.     
  1344.     SetCursor (&qd.arrow);
  1345. }
  1346.  
  1347.  
  1348. short    DisplayDNDDialog (DNWindowPtr dnWindow)
  1349. {
  1350.     DialogPtr    theDialog;
  1351.     short        itemHit;
  1352.     short        returnValue;
  1353.     DNDAttribHandle    theDNDAttrib = dnWindow->fDNDAttrib;
  1354.     
  1355.     theDialog = GetNewDialog (rDNDDLOG, nil, (WindowPtr)(-1L));
  1356.     if (theDialog == nil) {
  1357.         AlertUser ("\pUnable to get a DLOG resource !", ResError());
  1358.         return (-1);
  1359.     }
  1360.     
  1361.     PrepareDNDDLOGUserItems (theDialog);
  1362.     PutDNDAttribToDialog (theDialog, theDNDAttrib);
  1363.  
  1364.     ShowWindow (theDialog);
  1365.     
  1366.     ModalDialog (gStandardFilterUPP, &itemHit);    
  1367.         
  1368.     HideWindow (theDialog);
  1369.     
  1370.     switch (itemHit) {
  1371.         case ok :
  1372.             PutDialogSetupToDNDAttrib (theDialog, theDNDAttrib);
  1373.             if ((returnValue = SetDND (dnWindow)) == noErr)
  1374.                 returnValue = ok;
  1375.                 
  1376.             break;
  1377.         
  1378.         default :
  1379.             returnValue = cancel;
  1380.     }
  1381.     
  1382.     DisposDialog (theDialog);
  1383.     
  1384.     return (returnValue);
  1385. }
  1386.  
  1387.  
  1388. void    PutDNDAttribToDialog (DialogPtr theDialog, DNDAttribHandle theDNDAttrib)
  1389. {
  1390.     short    itemKind;
  1391.     Handle    itemHand;
  1392.     Rect    itemRect;
  1393.     
  1394.     GetDItem (theDialog, kDNDPopup, &itemKind, &itemHand, &itemRect);
  1395.     SetCtlValue ((ControlHandle) itemHand, (**theDNDAttrib).dndType + 1); // dndtype starts at 0
  1396. }
  1397.  
  1398.  
  1399. void    PutDialogSetupToDNDAttrib (DialogPtr theDialog, DNDAttribHandle theDNDAttrib)
  1400. {
  1401.     short    itemKind;
  1402.     Handle    itemHand;
  1403.     Rect    itemRect;
  1404.     
  1405.     GetDItem (theDialog, kDNDPopup, &itemKind, &itemHand, &itemRect);
  1406.     (**theDNDAttrib).dndType = GetCtlValue ((ControlHandle) itemHand) - 1;
  1407. }
  1408.  
  1409.  
  1410. OSErr    SetDND (DNWindowPtr dnWindow)
  1411. {
  1412.     OSErr                errCode = noErr;
  1413.     DNDAttribHandle        tDNDAttrib = dnWindow->fDNDAttrib;
  1414.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  1415.     
  1416.     if (dnHand) {    
  1417.         errCode = TELDNDSet (dnHand, (*tDNDAttrib)->dndType);
  1418.     
  1419.         if (errCode == noErr)
  1420.             PutLine (gLogWindow, "DND is set successfully");
  1421.         else
  1422.             PutCLine (gLogWindow, kErrorColor, "### TELDNDSet fails : %d", errCode);
  1423.     }
  1424.     
  1425.     return (errCode);
  1426. }
  1427.  
  1428.  
  1429. OSErr    CancelDND (DNWindowPtr dnWindow)
  1430. {
  1431.     OSErr                errCode = noErr;
  1432.     DNDAttribHandle        tDNDAttrib = dnWindow->fDNDAttrib;
  1433.     TELDNHandle    dnHand = dnWindow->fDNHandle;
  1434.  
  1435.     if (dnHand) {
  1436.         errCode = TELDNDClear (dnHand, (*tDNDAttrib)->dndType);
  1437.         
  1438.         if (errCode == noErr)
  1439.             PutLine (gLogWindow, "DND is canceled successfully");
  1440.         else
  1441.             PutCLine (gLogWindow, kErrorColor, "### TELDNDClear fails : %d", errCode);
  1442.     }
  1443.     
  1444.     return (errCode);
  1445. }
  1446.  
  1447.  
  1448. void    PrepareCallPickupDLOGUserItems (DialogPtr theDialog)
  1449. {
  1450.     short    itemType;
  1451.     Handle    item;
  1452.     Rect    box;
  1453.     CursHandle     watch = GetCursor(watchCursor);
  1454.     
  1455.     if (watch != nil)
  1456.         SetCursor (*watch);
  1457.     
  1458.     GetDItem (theDialog, kCallPickupBox1, &itemType, &item, &box);
  1459.     SetDItem (theDialog, kCallPickupBox1, itemType, (Handle) gDrawBoxUPP, &box);
  1460.     
  1461.     GetDItem (theDialog, kCallPickupDefault, &itemType, &item, &box);
  1462.     SetDItem (theDialog, kCallPickupDefault, itemType, (Handle) gDrawDefaultUPP, &box);
  1463.     
  1464.     if (watch != nil)
  1465.         ReleaseResource ((Handle) watch);
  1466.     
  1467.     SetCursor (&qd.arrow);
  1468. }
  1469.  
  1470.  
  1471. short    DisplayCallPickupDialog (DNWindowPtr dnWindow)
  1472. {
  1473.     DialogPtr    theDialog;
  1474.     short        itemHit;
  1475.     short        returnValue;
  1476.     CallPickupAttribHandle    theCallPickupAttrib = dnWindow->fCallPickupAttrib;
  1477.     
  1478.     theDialog = GetNewDialog (rCallPickupDLOG, nil, (WindowPtr)(-1L));
  1479.     if (theDialog == nil) {
  1480.         AlertUser ("\pUnable to get a DLOG resource !", ResError());
  1481.         return (-1);
  1482.     }
  1483.     
  1484.     PrepareCallPickupDLOGUserItems (theDialog);
  1485.     PutCallPickupAttribToDialog (theDialog, theCallPickupAttrib);
  1486.  
  1487.     ShowWindow (theDialog);
  1488.     
  1489.     ModalDialog (gStandardFilterUPP, &itemHit);    
  1490.         
  1491.     HideWindow (theDialog);
  1492.     
  1493.     switch (itemHit) {
  1494.         case ok :
  1495.             PutDialogSetupToCallPickupAttrib (theDialog, theCallPickupAttrib);
  1496.             returnValue = ok;
  1497.                 
  1498.             break;
  1499.         
  1500.         default :
  1501.             returnValue = cancel;
  1502.     }
  1503.     
  1504.     DisposDialog (theDialog);
  1505.     
  1506.     return (returnValue);
  1507. }
  1508.  
  1509.  
  1510. void    PutCallPickupAttribToDialog (DialogPtr theDialog, CallPickupAttribHandle theCallPickupAttrib)
  1511. {
  1512.     short    itemKind;
  1513.     Handle    itemHand;
  1514.     Rect    itemRect;
  1515.     
  1516.     GetDItem (theDialog, kCallPickupNumber, &itemKind, &itemHand, &itemRect);
  1517.     SetIText (itemHand, (*theCallPickupAttrib)->pickupDN);
  1518.     SelIText (theDialog, kCallPickupNumber, 0, 32767);
  1519. }
  1520.  
  1521.  
  1522. void    PutDialogSetupToCallPickupAttrib (DialogPtr theDialog, CallPickupAttribHandle theCallPickupAttrib)
  1523. {
  1524.     short    itemKind;
  1525.     Handle    itemHand;
  1526.     Rect    itemRect;
  1527.     
  1528.     GetDItem (theDialog, kCallPickupNumber, &itemKind, &itemHand, &itemRect);
  1529.     GetIText (itemHand, (*theCallPickupAttrib)->pickupDN);
  1530. }
  1531.  
  1532.  
  1533. void    PrepareMakeACallDLOGUserItems (DialogPtr theDialog)
  1534. {
  1535.     short    itemType;
  1536.     Handle    item;
  1537.     Rect    box;
  1538.     CursHandle     watch = GetCursor(watchCursor);
  1539.     
  1540.     if (watch != nil)
  1541.         SetCursor (*watch);
  1542.     
  1543.     GetDItem (theDialog, kMakeACallBox1, &itemType, &item, &box);
  1544.     SetDItem (theDialog, kMakeACallBox1, itemType, (Handle) gDrawBoxUPP, &box);
  1545.     
  1546.     GetDItem (theDialog, kMakeACallDefault, &itemType, &item, &box);
  1547.     SetDItem (theDialog, kMakeACallDefault, itemType, (Handle) gDrawDefaultUPP, &box);
  1548.     
  1549.     if (watch != nil)
  1550.         ReleaseResource ((Handle) watch);
  1551.     
  1552.     SetCursor (&qd.arrow);
  1553. }
  1554.  
  1555.  
  1556. short    DisplayMakeACallDialog (DNWindowPtr dnWindow)
  1557. {
  1558.     DialogPtr    theDialog;
  1559.     short        itemHit;
  1560.     short        returnValue;
  1561.     MakeACallAttribHandle    theMakeACallAttrib = dnWindow->fMakeACallAttrib;
  1562.     
  1563.     theDialog = GetNewDialog (rMakeACallDLOG, nil, (WindowPtr)(-1L));
  1564.     if (theDialog == nil) {
  1565.         AlertUser ("\pUnable to get a DLOG resource !", ResError());
  1566.         return (-1);
  1567.     }
  1568.     
  1569.     PrepareMakeACallDLOGUserItems (theDialog);
  1570.     PutMakeACallAttribToDialog (theDialog, theMakeACallAttrib);
  1571.     
  1572.     ShowWindow (theDialog);
  1573.     
  1574.     ModalDialog (gStandardFilterUPP, &itemHit);    
  1575.         
  1576.     HideWindow (theDialog);
  1577.     
  1578.     switch (itemHit) {
  1579.         case ok :
  1580.             PutDialogSetupToMakeACallAttrib (theDialog, theMakeACallAttrib);
  1581.             returnValue = ok;
  1582.                 
  1583.             break;
  1584.         
  1585.         default :
  1586.             returnValue = cancel;
  1587.     }
  1588.     
  1589.     DisposDialog (theDialog);
  1590.     
  1591.     return (returnValue);
  1592. }
  1593.  
  1594.  
  1595. void    PutMakeACallAttribToDialog (DialogPtr theDialog, MakeACallAttribHandle theMakeACallAttrib)
  1596. {
  1597.     short    itemKind;
  1598.     Handle    itemHand;
  1599.     Rect    itemRect;
  1600.     Str255    tStr;
  1601.     
  1602.     GetDItem (theDialog, kMakeACallNumber, &itemKind, &itemHand, &itemRect);
  1603.     SetIText (itemHand, (*theMakeACallAttrib)->destDN);
  1604.     SelIText (theDialog, kMakeACallNumber, 0, 32767);
  1605.     
  1606.     GetDItem (theDialog, kMakeACallName, &itemKind, &itemHand, &itemRect);
  1607.     SetIText (itemHand, (*theMakeACallAttrib)->destName);
  1608.     
  1609.     GetDItem (theDialog, kMakeACallSubAddr, &itemKind, &itemHand, &itemRect);
  1610.     SetIText (itemHand, (*theMakeACallAttrib)->subAddr);
  1611.     
  1612.     GetDItem (theDialog, kMakeACallUserInfo, &itemKind, &itemHand, &itemRect);
  1613.     SetIText (itemHand, (*theMakeACallAttrib)->userUserInfo);
  1614.  
  1615.     GetDItem (theDialog, kMakeACallBearer, &itemKind, &itemHand, &itemRect);
  1616.     NumToString ((*theMakeACallAttrib)->bearerType, tStr);
  1617.     SetIText (itemHand, tStr);
  1618.  
  1619.     GetDItem (theDialog, kMakeACallRate, &itemKind, &itemHand, &itemRect);
  1620.     NumToString ((*theMakeACallAttrib)->rate, tStr);
  1621.     SetIText (itemHand, tStr);
  1622. }
  1623.  
  1624.  
  1625. void    PutDialogSetupToMakeACallAttrib (DialogPtr theDialog, MakeACallAttribHandle theMakeACallAttrib)
  1626. {
  1627.     short    itemKind;
  1628.     Handle    itemHand;
  1629.     Rect    itemRect;
  1630.     long    tlong;
  1631.     Str255    tStr;
  1632.     
  1633.     GetDItem (theDialog, kMakeACallNumber, &itemKind, &itemHand, &itemRect);
  1634.     GetIText (itemHand, (*theMakeACallAttrib)->destDN);
  1635.     GetDItem (theDialog, kMakeACallName, &itemKind, &itemHand, &itemRect);
  1636.     GetIText (itemHand, (*theMakeACallAttrib)->destName);
  1637.     GetDItem (theDialog, kMakeACallSubAddr, &itemKind, &itemHand, &itemRect);
  1638.     GetIText (itemHand, (*theMakeACallAttrib)->subAddr);
  1639.     GetDItem (theDialog, kMakeACallUserInfo, &itemKind, &itemHand, &itemRect);
  1640.     GetIText (itemHand, (*theMakeACallAttrib)->userUserInfo);
  1641.  
  1642.     GetDItem (theDialog, kMakeACallBearer, &itemKind, &itemHand, &itemRect);
  1643.     GetIText (itemHand, tStr);
  1644.     StringToNum (tStr, &tlong);
  1645.     (*theMakeACallAttrib)->bearerType = tlong;
  1646.  
  1647.     GetDItem (theDialog, kMakeACallRate, &itemKind, &itemHand, &itemRect);
  1648.     GetIText (itemHand, tStr);
  1649.     StringToNum (tStr, &tlong);
  1650.     (*theMakeACallAttrib)->rate = tlong;
  1651. }
  1652.  
  1653.  
  1654. void    PrepareGetParkIDDLOGUserItems (DialogPtr theDialog)
  1655. {
  1656.     short    itemType;
  1657.     Handle    item;
  1658.     Rect    box;
  1659.     CursHandle     watch = GetCursor(watchCursor);
  1660.     
  1661.     if (watch != nil)
  1662.         SetCursor (*watch);
  1663.     
  1664.     GetDItem (theDialog, kGetParkIDBox1, &itemType, &item, &box);
  1665.     SetDItem (theDialog, kGetParkIDBox1, itemType, (Handle) gDrawBoxUPP, &box);
  1666.     
  1667.     GetDItem (theDialog, kGetParkIDDefault, &itemType, &item, &box);
  1668.     SetDItem (theDialog, kGetParkIDDefault, itemType, (Handle) gDrawDefaultUPP, &box);
  1669.     
  1670.     if (watch != nil)
  1671.         ReleaseResource ((Handle) watch);
  1672.     
  1673.     SetCursor (&qd.arrow);
  1674. }
  1675.  
  1676.  
  1677. short    DisplayGetParkIDDialog (Str255 parkID)
  1678. {
  1679.     DialogPtr    theDialog;
  1680.     short        itemHit;
  1681.     short        returnValue;
  1682.     short        itemKind;
  1683.     Handle        itemHand;
  1684.     Rect        itemRect;
  1685.     
  1686.     theDialog = GetNewDialog (rGetParkIDDLOG, nil, (WindowPtr)(-1L));
  1687.     if (theDialog == nil) {
  1688.         AlertUser ("\pUnable to get a DLOG resource !", ResError());
  1689.         return (-1);
  1690.     }
  1691.     
  1692.     PrepareGetParkIDDLOGUserItems (theDialog);
  1693.     
  1694.     ShowWindow (theDialog);
  1695.     
  1696.     ModalDialog (gStandardFilterUPP, &itemHit);    
  1697.         
  1698.     HideWindow (theDialog);
  1699.     
  1700.     switch (itemHit) {
  1701.         case ok :
  1702.             GetDItem (theDialog, kGetParkIDNumber, &itemKind, &itemHand, &itemRect);
  1703.             GetIText (itemHand, parkID);
  1704.             returnValue = ok;
  1705.             break;
  1706.         
  1707.         default :
  1708.             returnValue = cancel;
  1709.     }
  1710.     
  1711.     DisposDialog (theDialog);
  1712.     
  1713.     return (returnValue);
  1714. }
  1715.  
  1716.  
  1717. void    DumpSelectedCAInfo (DNWindowPtr dnWindow)
  1718. {
  1719.     short            count;
  1720.     Cell            tCell;
  1721.     CAWindowPtr        tCAWindow;
  1722.  
  1723.     SetPt (&tCell, 0, 0);
  1724.     while (LGetSelect (true, &tCell, dnWindow->fCAList)) {
  1725.         tCAWindow = dnWindow->fCAWindowList;
  1726.         count = 0;
  1727.         while (count++ < tCell.v)
  1728.             tCAWindow = tCAWindow->next;
  1729.  
  1730.         DumpCAInfo (tCAWindow->fCAHandle);
  1731.         if (! LNextCell (true, true, &tCell, dnWindow->fCAList))
  1732.             break;
  1733.     }
  1734. }
  1735.  
  1736.  
  1737. void    DumpSelectedCAState (DNWindowPtr dnWindow)
  1738. {
  1739.     short            count;
  1740.     Cell            tCell;
  1741.     CAWindowPtr        tCAWindow;
  1742.  
  1743.     SetPt (&tCell, 0, 0);
  1744.     while (LGetSelect (true, &tCell, dnWindow->fCAList)) {
  1745.         tCAWindow = dnWindow->fCAWindowList;
  1746.         count = 0;
  1747.         while (count++ < tCell.v)
  1748.             tCAWindow = tCAWindow->next;
  1749.  
  1750.         DumpCAState (tCAWindow->fCAHandle);
  1751.         PutLine (gLogWindow, " caHand               = %08x", tCAWindow->fCAHandle);
  1752.         if (! LNextCell (true, true, &tCell, dnWindow->fCAList))
  1753.             break;
  1754.     }
  1755. }
  1756.  
  1757.  
  1758. void    ShowCAWindow (DNWindowPtr dnWindow, short whichCA)
  1759. {
  1760.     short        count = 0;
  1761.     CAWindowPtr    tCAWindow = dnWindow->fCAWindowList;
  1762.     
  1763.     while (count++ < whichCA)
  1764.         tCAWindow = tCAWindow->next;
  1765.         
  1766.     ShowWindow ((WindowPtr) tCAWindow);
  1767.     SelectWindow ((WindowPtr) tCAWindow);
  1768. }
  1769.  
  1770.  
  1771. void    AppendCAList (DNWindowPtr dnWindow, TELCAHandle caHand)
  1772. {
  1773.     CAWindowPtr    *caWindow = &dnWindow->fCAWindowList;
  1774.     ListHandle    theList = dnWindow->fCAList;
  1775.     Cell        tCell;
  1776.     Str31         title;
  1777.     OSErr        errCode;
  1778.     Str255        tString;
  1779.     short        len;
  1780.     
  1781.     while (*caWindow != nil)
  1782.         caWindow = &(*caWindow)->next;
  1783.         
  1784.     sprintf ((char *) title, "caHand = 0x%x", caHand);
  1785.     *caWindow = CreateCAWindow (caHand, (char *) title);
  1786.     (*caHand)->refCon = (long) dnWindow;
  1787.     if (*caWindow != nil) {
  1788.         SetPt (&tCell, 0, (*theList)->dataBounds.bottom);
  1789.         LAddRow (1, (*theList)->dataBounds.bottom, theList);
  1790.         
  1791.         len = sprintf ((char *) tString, "%08x", caHand);
  1792.         LSetCell (tString, len, tCell, theList);
  1793.         
  1794.         ClearAllSelectedCells (theList);
  1795.         LSetSelect (true, tCell, theList);
  1796.     }
  1797.     else
  1798.         if ((errCode = TELCADispose (caHand)) != noErr)
  1799.             PutCLine (gLogWindow, kErrorColor, "### TELCADispose failed : %d", errCode);
  1800. }
  1801.  
  1802.  
  1803. short    SearchCAList (DNWindowPtr dnWindow, TELCAHandle caHand)
  1804. {
  1805.     CAWindowPtr    caWindow;
  1806.     short        returnValue = -1;
  1807.     short        row = 0;
  1808.     
  1809.     if (dnWindow != nil) {
  1810.         caWindow = dnWindow->fCAWindowList;
  1811.         while (caWindow != nil) {
  1812.             if (caWindow->fCAHandle == caHand) {
  1813.                 returnValue = row;
  1814.                 break;
  1815.             }
  1816.             ++row;
  1817.             caWindow = caWindow->next;
  1818.         }
  1819.     }
  1820.     
  1821.     return (returnValue);
  1822. }
  1823.  
  1824.  
  1825. void    RemoveFromCAList (DNWindowPtr dnWindow, TELCAHandle caHand)
  1826. {
  1827.     CAWindowPtr    *previous = &dnWindow->fCAWindowList, caWindow;
  1828.     short        index = 0, row;
  1829.     
  1830.     row = SearchCAList (dnWindow, caHand);
  1831.     if (row < 0)
  1832.         PutCLine (gLogWindow, kErrorColor, "### Can't find caHand (%08x) in caList", caHand);
  1833.     else {
  1834.         if (*previous) {
  1835.             while ((caWindow = *previous) && (index != row)) {
  1836.                 ++index;
  1837.                 previous = &caWindow->next;
  1838.             }
  1839.             
  1840.             if (index != row)
  1841.                 PutCLine (gLogWindow, kErrorColor, "### Can't delete row %d because list has only %d rows", row, index);
  1842.             else {
  1843.                 LDelRow (1, row, dnWindow->fCAList);
  1844.                 *previous = caWindow->next;
  1845.                 DisposeCAWindow (caWindow);
  1846.             }
  1847.         }
  1848.     }
  1849. }
  1850.  
  1851.  
  1852. DNWindowPtr    GetDNWindow (TELCAHandle caHand)
  1853. {
  1854.     DNWindowPtr    dnWindow = nil;
  1855.     
  1856.     dnWindow = gTelWindow->fDNWindowList;
  1857.     while (dnWindow != nil) {
  1858.         if (dnWindow->fDNHandle == (*caHand)->hTELDN)
  1859.             break;
  1860.         
  1861.         dnWindow = dnWindow->next;
  1862.     }
  1863.     
  1864.     return (dnWindow);
  1865. }
  1866.  
  1867.  
  1868. short    GetCAIndex (DNWindowPtr dnWindow, TELCAHandle caHand)
  1869. {
  1870.     short        row = 0;
  1871.     CAWindowPtr    caWindow = dnWindow->fCAWindowList;
  1872.     
  1873.     while (caWindow) {
  1874.         if (caWindow->fCAHandle == caHand)
  1875.             break;
  1876.             
  1877.         caWindow = caWindow->next;
  1878.         ++row;
  1879.     }
  1880.     
  1881.     return (row);
  1882. }
  1883.  
  1884.  
  1885. void    UpdateCAListState (DNWindowPtr dnWindow, TELCAHandle caHand)
  1886. {
  1887.     short        len, row;
  1888.     Str255        tString;
  1889.     char        *stateStr;
  1890.     Cell        tCell;
  1891.  
  1892.     if (dnWindow != nil) {
  1893.     
  1894.         (void) TELGetCAInfo (caHand);
  1895.         
  1896.         GetCAStateStr (caHand, &stateStr);
  1897.         
  1898.         len = sprintf ((char *) tString, "%08x   %s (%d)", caHand, stateStr, (*caHand)->callType);
  1899.         
  1900.         if (len >= 0 ) {
  1901.             row = GetCAIndex (dnWindow, caHand);
  1902.             SetPt (&tCell, 0, row);
  1903.             LSetCell (tString, len, tCell, dnWindow->fCAList);
  1904.         }
  1905.     }
  1906.     else
  1907.         PutCLine (gLogWindow, kErrorColor, "### Can't find the corresponding dnWindow");
  1908. }
  1909.  
  1910.  
  1911. #pragma segment DNWindow
  1912. TELCAHandle    GetNthCA (short n, DNWindowPtr dnWindow)
  1913. {
  1914.     CAWindowPtr        caWindow = dnWindow->fCAWindowList;
  1915.     short            index = 0;
  1916.     TELCAHandle        caHand = nil;
  1917.     
  1918.     if (n)
  1919.     {
  1920.         while (caWindow) {                                
  1921.             if (++index == n)
  1922.                 return (caWindow->fCAHandle);
  1923.             
  1924.             caWindow = caWindow->next;
  1925.         }
  1926.     }
  1927.     
  1928.     return (caHand);
  1929. }
  1930.  
  1931.  
  1932.